

using GalFrameWork.Service;
using GalFrameWork.Services;
using GalFrameWork.Services.Impl;
using GalFrameWork.ViewModel;

namespace GalFrameWork;


public class ServiceLocator
{
    private IServiceProvider _serviceProvider;



    public IRouteService RouteService =>
        _serviceProvider.GetService<IRouteService>();

    //相当于get函数，得到的返回值为xxx。只要调用这个属性，就会通过_serviceProvider
    //的函数得到一个<MainPageProvider>类型的实列
    public MainPageViewModel MainPageViewModel =>
        _serviceProvider.GetService<MainPageViewModel>();//依赖注入，ioc
    public SceneEditPageViewModel SceneEditPageViewModel =>
        _serviceProvider.GetService<SceneEditPageViewModel>();

    public ServiceLocator()
    {
        var serviceCollection = new ServiceCollection();

        serviceCollection
            .AddSingleton<IRouteService, RouteService>();
        serviceCollection
            .AddSingleton<IContentNavigationService, ContentNavigationService>();
        serviceCollection
            .AddSingleton<IRootNavigationService, RootNavigationService>();
        serviceCollection
            .AddSingleton<IDialogStorage, DialogStorage>();
        serviceCollection
            .AddSingleton<ISceneStorage, SceneStorage>();
        
        serviceCollection.AddSingleton<MainPageViewModel>();
        serviceCollection.AddSingleton<SceneEditPageViewModel>();

        _serviceProvider = serviceCollection.BuildServiceProvider();
        }
    }
